﻿using System.Threading;

namespace MessagingWPF.Infrastructure
{
	/// <summary>
	/// A little helper class that provides access to the 
	/// current <see cref="SynchronizationContext"/> and
	/// creates no context exists.
	/// </summary>
	public static class SyncFactory
	{
		/// <summary>
		/// Gets the current <see cref="SynchronizationContext"/>.
		/// </summary>
		public static SynchronizationContext CurrentContext
		{
			get
			{
				var currentContext = SynchronizationContext.Current;

				if (currentContext == null)
				{
					currentContext = new SynchronizationContext();
					SynchronizationContext.SetSynchronizationContext(currentContext);
				}

				return currentContext;
			}
		}
	}
}